
#if defined(WIN32) || defined(WIN64)
#pragma unmanaged
#endif

#include <Liberty3D/Engine/PosixException.h>

#include <sstream>

using namespace Liberty::Engine;

static std::string ToError(int err, const std::string& string) {
    std::stringstream f;
    
    f << string;
#ifdef WIN32
    char errMsg[256];

    strerror_s(errMsg, err);

    f << "\n\nError code: " << err << "\n" << errMsg;
#else
    f << "\n\nError code: " << err << "\n" << strerror(err);
#endif
    return f.str();
}

PosixException::PosixException(int errorCode) : std::runtime_error(ToError(errorCode, "Unknown error")), _errorCode(errorCode) {
}

PosixException::PosixException(int errorCode, const std::string& desc) : std::runtime_error(ToError(errorCode, desc)), _errorCode(errorCode) {
}
